/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package POJOS;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author jim
 */
@Entity
@Table(name = "ARTIST")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Artist.findAll", query = "SELECT a FROM Artist a"),
    @NamedQuery(name = "Artist.findByIdArtist", query = "SELECT a FROM Artist a WHERE a.idArtist = :idArtist"),
    @NamedQuery(name = "Artist.findByFirstname", query = "SELECT a FROM Artist a WHERE a.firstname = :firstname"),
    @NamedQuery(name = "Artist.findByLastname", query = "SELECT a FROM Artist a WHERE a.lastname = :lastname"),
    @NamedQuery(name = "Artist.findByArtisticName", query = "SELECT a FROM Artist a WHERE a.artisticName = :artisticName"),
    @NamedQuery(name = "Artist.findBySex", query = "SELECT a FROM Artist a WHERE a.sex = :sex"),
    @NamedQuery(name = "Artist.findByBirthday", query = "SELECT a FROM Artist a WHERE a.birthday = :birthday"),
    @NamedQuery(name = "Artist.findByBirthPlace", query = "SELECT a FROM Artist a WHERE a.birthPlace = :birthPlace")})
public class Artist implements Serializable {
    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "ID_ARTIST")
    private Integer idArtist;
    @Basic(optional = false)
    @Column(name = "FIRSTNAME")
    private String firstname;
    @Basic(optional = false)
    @Column(name = "LASTNAME")
    private String lastname;
    @Basic(optional = false)
    @Column(name = "ARTISTIC_NAME")
    private String artisticName;
    @Basic(optional = false)
    @Column(name = "SEX")
    private String sex;
    @Basic(optional = false)
    @Column(name = "BIRTHDAY")
    @Temporal(TemporalType.DATE)
    private Date birthday;
    @Basic(optional = false)
    @Column(name = "BIRTH_PLACE")
    private String birthPlace;
    @JoinTable(name = "MUSIC_GROUP_ARTIST", joinColumns = {
        @JoinColumn(name = "ID_ARTIST", referencedColumnName = "ID_ARTIST")}, inverseJoinColumns = {
        @JoinColumn(name = "ID_MUSIC_GROUP", referencedColumnName = "ID_MUSIC_GROUP")})
    @ManyToMany
    private Collection<MusicGroup> musicGroupCollection;
    @JoinColumn(name = "ID_MUSIC_GENRE", referencedColumnName = "ID_MUSIC_GENRE")
    @ManyToOne(optional = false)
    private MusicGenre idMusicGenre;
    @OneToMany(mappedBy = "idArtist")
    private Collection<Album> albumCollection;

    public Artist() {
    }

    public Artist(Integer idArtist) {
        this.idArtist = idArtist;
    }

    public Artist(Integer idArtist, String firstname, String lastname, String artisticName, String sex, Date birthday, String birthPlace) {
        this.idArtist = idArtist;
        this.firstname = firstname;
        this.lastname = lastname;
        this.artisticName = artisticName;
        this.sex = sex;
        this.birthday = birthday;
        this.birthPlace = birthPlace;
    }

    //Επιπλέον δημιουργός για σύνδεση στη βάση
    public Artist(Integer idArtist, String firstname, String lastname, String artisticName, String sex, Date birthday, String birthPlace, MusicGenre idMusicGenre) {
        this.idArtist = idArtist;
        this.firstname = firstname;
        this.lastname = lastname;
        this.artisticName = artisticName;
        this.sex = sex;
        this.birthday = birthday;
        this.birthPlace = birthPlace;
        this.idMusicGenre= idMusicGenre;
    }
    
    public Integer getIdArtist() {
        return idArtist;
    }

    public void setIdArtist(Integer idArtist) {
        Integer oldIdArtist = this.idArtist;
        this.idArtist = idArtist;
        changeSupport.firePropertyChange("idArtist", oldIdArtist, idArtist);
    }

    public String getFirstname() {
        return firstname;
    }

    public void setFirstname(String firstname) {
        String oldFirstname = this.firstname;
        this.firstname = firstname;
        changeSupport.firePropertyChange("firstname", oldFirstname, firstname);
    }

    public String getLastname() {
        return lastname;
    }

    public void setLastname(String lastname) {
        String oldLastname = this.lastname;
        this.lastname = lastname;
        changeSupport.firePropertyChange("lastname", oldLastname, lastname);
    }

    public String getArtisticName() {
        return artisticName;
    }

    public void setArtisticName(String artisticName) {
        String oldArtisticName = this.artisticName;
        this.artisticName = artisticName;
        changeSupport.firePropertyChange("artisticName", oldArtisticName, artisticName);
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        String oldSex = this.sex;
        this.sex = sex;
        changeSupport.firePropertyChange("sex", oldSex, sex);
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        Date oldBirthday = this.birthday;
        this.birthday = birthday;
        changeSupport.firePropertyChange("birthday", oldBirthday, birthday);
    }

    public String getBirthPlace() {
        return birthPlace;
    }

    public void setBirthPlace(String birthPlace) {
        String oldBirthPlace = this.birthPlace;
        this.birthPlace = birthPlace;
        changeSupport.firePropertyChange("birthPlace", oldBirthPlace, birthPlace);
    }

    @XmlTransient
    public Collection<MusicGroup> getMusicGroupCollection() {
        return musicGroupCollection;
    }

    public void setMusicGroupCollection(Collection<MusicGroup> musicGroupCollection) {
        this.musicGroupCollection = musicGroupCollection;
    }

    public MusicGenre getIdMusicGenre() {
        return idMusicGenre;
    }

    public void setIdMusicGenre(MusicGenre idMusicGenre) {
        MusicGenre oldIdMusicGenre = this.idMusicGenre;
        this.idMusicGenre = idMusicGenre;
        changeSupport.firePropertyChange("idMusicGenre", oldIdMusicGenre, idMusicGenre);
    }

    @XmlTransient
    public Collection<Album> getAlbumCollection() {
        return albumCollection;
    }

    public void setAlbumCollection(Collection<Album> albumCollection) {
        this.albumCollection = albumCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idArtist != null ? idArtist.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Artist)) {
            return false;
        }
        Artist other = (Artist) object;
        if ((this.idArtist == null && other.idArtist != null) || (this.idArtist != null && !this.idArtist.equals(other.idArtist))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "POJOS.Artist[ idArtist=" + idArtist + " ]";
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.removePropertyChangeListener(listener);
    }
    
}
